<%@ taglib prefix="maxlength" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: Easy
  Date: 2017-09-27
  Time: 15:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>

<div class="row">
    <div class="col-md-12">

        <form  class="form-horizontal" id="editLockForm" >
            <div class="panel panel-default">
                <div class="panel-body">

                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label">地锁编号</label>
                                <div class="col-md-9">
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="fa fa-eye"></span></span>
                                        <input type="hidden" class="form-control" name="id" value="${lock.id}"  >
                                        <input type="text" class="form-control" required name="number" value="${lock.number}"  >
                                    </div>
                                    <span class="help-block">请输入地锁编号</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label">地锁开关</label>
                                <div class="col-md-9">
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="fa fa-sort"></span></span>
                                        <select class="form-control" name="lockIo" id="lockIo">
                                            <option value="1" <c:if test="${lock.lockIo==1}">selected</c:if>>开</option>
                                            <option value="0" <c:if test="${lock.lockIo==0}">selected</c:if>>关</option>
                                        </select>
                                    </div>
                                    <span class="help-block">请选择地锁的开关</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label">绑定状态</label>
                                <div class="col-md-9">
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="fa fa-sort"></span></span>
                                        <select class="form-control" name="bindingState" id="bindingState">
                                            <option value="0" <c:if test="${lock.bindingState==0}">selected</c:if>>未被绑定</option>
                                            <option value="1" <c:if test="${lock.bindingState==1}">selected</c:if>>已被绑定</option>
                                        </select>
                                    </div>
                                    <span class="help-block">请选择绑定状态</span>
                                </div>
                            </div>
                        </div>


                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label">停车场</label>
                                <div class="col-md-9">
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="fa fa-eye"></span></span>
                                        <select class="form-control" required id="parkingId" name="parkingId" >
                                            <c:forEach items="${parkingList}" var="item">
                                                <option value="${item.id}"  <c:if test="${lock.parkingId==item.id}">selected</c:if>>${item.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <span class="help-block">请选择所属停车场</span>
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-md-3 control-label">当前状态</label>
                                <div class="col-md-9">
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="fa fa-sort"></span></span>
                                        <select class="form-control" name="status" id="status">
                                            <option value="0" <c:if test="${lock.status==0}">selected</c:if>>空闲</option>
                                            <option value="1" <c:if test="${lock.status==1}">selected</c:if>>已预约</option>
                                            <option value="2" <c:if test="${lock.status==2}">selected</c:if>>使用中</option>
                                            <option value="3" <c:if test="${lock.status==3}">selected</c:if>>电压不足</option>
                                        </select>
                                    </div>
                                    <span class="help-block">请选择当前地锁的状态</span>
                                </div>
                            </div>

                        </div>

                    </div>

                </div>
                <div class="panel-footer">
                    <button class="btn btn-default">清除</button>
                    <input type="button"class="btn btn-primary" onclick="edit()" value="修改">
                </div>
            </div>
        </form>

    </div>
</div>
<script>
    function getFloor() {
        $("#floor").find("option").remove();
        var parkingId=$('#parkingId option:selected') .val();
        var status=$('#status option:selected') .val();
        var lockIo=$('#lockIo option:selected') .val();
        if(parkingId !=undefined  && parkingId !=0){

            $.ajax({
                type:"POST",
                url:"/car/parking/selectById",
                data:{"parkingId":parkingId},
                dataType:"json",
                success:function (data) {
                    for(var i=1; i<=data.floor; i++){
                        $("#floor").append('<option value="' + i + '">' + i+"层" + '</option>')
                    };
                }
            });
        }

    }

    function edit() {
        var param = serializeForm("editLockForm");
        var parkingId=$('#parkingId option:selected').val();
        var status=$('#status option:selected') .val();
        var lockIo=$('#lockIo option:selected').val();
        var bindingState = $('#bindingState option:selected').val();
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: param +"&parkingId=" + parkingId+"&lockIo=" + lockIo+"&bindingState=" + bindingState+"&status=" + status,
            async: true,
            url: '/car/lock/update',
            success: function (data) {
                if (data.success){
                    layer.msg(data.msg,{icon:1,time:1000},function () {
                        layer.close(top.layer_lockEdit);
                        reloadPage();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            },
            error: function () {
                alert("修改未成功")
            }
        })
    }

</script>
